package com.example.douyin.mine;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.douyin.R;
import com.example.douyin.adapter.MineVideoAdapter;
import com.example.douyin.db.DBUtils;
import com.example.lib_base_mvvm.entity.VideoEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MineFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MineFragment extends Fragment {
    List<VideoEntity.DataBean> list = new ArrayList<>();
    MineVideoAdapter mineVideoAdapter;
    private RecyclerView rv;


    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_mine, container, false);
        rv = inflate.findViewById(R.id.rv);

        mineVideoAdapter = new MineVideoAdapter(R.layout.item_video,list);
        rv.setAdapter(mineVideoAdapter);
        rv.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
       /* list = DBUtils.getInstance().getVideoDao().query();*/
      List<VideoEntity.DataBean> dataBeans = DBUtils.getInstance().getVideoDao().query();
        list.clear();
        list.addAll(dataBeans);
        mineVideoAdapter.notifyDataSetChanged();


        return inflate;
    }
}